#!/bin/bash
source /root/shell_scripts/set_firewalld.sh
set_lamp() {
#关闭防火墙 关闭Selinux
set_firewalld
#安装httpd
yum -y install httpd &> /dev/null && echo -e  "\e[32mhttpd安装成功\e[0m"  || echo -e "\e[31mhttpd安装失败\e[0m"
sleep 0.5
#删除80端口下的进程
yum -y install lsof &> /dev/null
for pid in `lsof -i:80 | grep -v "PID"  | awk   '{print $2}'`;do 
kill -15 $pid
done
#启动httpd服务
systemctl enable --now  httpd &> /dev/null  && echo -e  "\e[32mhttpd配置成功\e[0m"  || echo -e "\e[31mhttpd配置失败\e[0m"
#配置httpd
yum -y install wget &> /devnull 
wget www.jd.com -O /var/www/html/index.html &> /dev/null && echo -e  "\e[32m前端页面配置成功\e[0m"  || echo -e "\e[31m前端页面配置失败\e[0m"
sleep 0.5
#重启httpd服务
systemctl restart httpd &> /dev/null 
sleep 0.5
curl -I  localhost:80 &> /dev/null && echo -e  "\e[32m配置成功\e[0m"  || echo -e "\e[31m配置失败\e[0m"
#初始化Mysql
wget https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm &> /dev/null
rpm -ivh mysql80-community-release-el7-11.noarch.rpm &> /dev/null
yum  -y install mysql mysql-server &> /dev/null
systemctl start mysqld
if [ $? -eq 0 ];then
   echo -e "\e[32m初始化成功\e[0m"
else
   echo -e "\e[31m初始化成功\e[0m"
fi
#配置Mysql
yum -y install expect &> /dev/null 
#获取Mysql默认密码
password=`grep "password" /var/log/mysqld.log |awk -F":" '{NR==1;print $NF}' | xargs`
#登录数据库并更改密码
read -s -p "输入你要更改的密码  " new_password
expect <<EOF
spawn mysql -uroot -p
expect "Enter password: "
send "$password\r"
expect "mysql> "
send "alter user root@'localhost' identified by '$new_password';\r"
expect "mysql> "
send "exit\r"
expect eof
EOF
}
